/**
 * Created by Galois on 2017/7/4.
 */

$(function(){
    console.log("加油");
    var mainLoading = false;
    getContent();

    function getData(result) {
        if(result.status==200){
            return result.data;
        }else{
            alert(result.messages||"获取信息错误");
            return null;
        }
    }

    function getContent(result){
        if (mainLoading) return;

        $.get("IndexJson/index.action",function (result, err) {
            var items = getData(result);
            appendContent(items);
        })

        mainLoading = true;
    }

    /*把获取到的列表信息填充入#List中*/
    function appendContent(items){
        console.log("appendContent");
        var contentMain;
        var listContentMain=[];
        items.forEach(function(itemMain){
            /*主页内容部分，六个格子*/
            listContentMain.push('<div class="main">');
            listContentMain.push('    <div class="main_content">');
            listContentMain.push('        <div class="news">');
            listContentMain.push('            <div class="news_title">');
            listContentMain.push('               <h>'+ itemMain.titleFront +'</h>');
            listContentMain.push('                <a href="'+ itemMain.moreFront +'">更多<img src="images/more_too.jpg"></a>');
            listContentMain.push('            </div>');
            listContentMain.push('            <div class="news_content">');
            listContentMain.push('                <div class="news_content">');
            listContentMain.push('                    <a href="'+ itemMain.imgFrontHref +'"><img src="'+ itemMain.imgFront +'" /></a>');
            listContentMain.push('               </div><!--news_content结束-->');
            listContentMain.push('            </div><!--news_content结束-->');
            listContentMain.push('        </div><!--news结束-->');
            listContentMain.push('        <div class="news2">');
            listContentMain.push('            <div class="news_title">');
            listContentMain.push('                <h>'+ itemMain.titleAdmin +'</h>');
            listContentMain.push('                <a href="'+ itemMain.moreAdmin +'">更多<img src="images/more_too.jpg"></a>');
            listContentMain.push('            </div><!--news_title结束-->');
            listContentMain.push('            <div class="news_content">');
            listContentMain.push('                <div class="news_content">');
            listContentMain.push('                   <a href="'+ itemMain.imgAdminHref +'" target="_blank" ><img src="'+ itemMain.imgAdmin +'" /></a>');
            listContentMain.push('                </div><!--news_content结束-->');
            listContentMain.push('            </div><!--news_content结束-->');
            listContentMain.push('        </div><!--news2结束-->');
            listContentMain.push('        <div class="news3">');
            listContentMain.push('            <div class="news_title">');
            listContentMain.push('                <h>'+ itemMain.titleMyHomePage +'</h>');
            listContentMain.push('                <a href="'+ itemMain.moreMyHomePage +'">更多<img src="images/more_too.jpg" /></a>');
            listContentMain.push('            </div><!--news_title结束-->');
            listContentMain.push('            <div class="news_content">');
            listContentMain.push('                <div class="news_content">');
            listContentMain.push('                    <a href="'+ itemMain.imgMyHomePageHref +'" target="_blank"><img src="'+ itemMain.imgMyHomePage +'" /></a>');
            listContentMain.push('                    </div><!--news_content结束-->');
            listContentMain.push('            </div><!--news_title3结束-->');
            listContentMain.push('        </div><!--news3结束-->');
            listContentMain.push('    </div><!--main_content结束-->');
            listContentMain.push('</div><!--main结束-->');

            listContentMain.push('<div class="main" id="main">');
            listContentMain.push('    <div class="main_content">');
            listContentMain.push('        <div class="news">');
            listContentMain.push('            <div class="news_title">');
            listContentMain.push('                <h>'+ itemMain.myArticleTitle +'</h>');
            listContentMain.push('                <a href="'+ itemMain.moreArticleTitle +'">更多<img src="images/more_too.jpg"></a>');
            listContentMain.push('           </div>');
            listContentMain.push('            <div class="news_content">');
            listContentMain.push('                <ul>');
            listContentMain.push('                    <li><i class="blog"></i><a target="_blank" href="'+ itemMain.myArticleHref[0] +'">'+ itemMain.myArticle[0] +'</a></li>');
            listContentMain.push('                    <li><i class="blog"></i><a target="_blank" href="'+ itemMain.myArticleHref[1] +'">'+ itemMain.myArticle[1] +'</a></li>');
            listContentMain.push('                    <li><i class="blog"></i><a target="_blank" href="'+ itemMain.myArticleHref[2] +'">'+ itemMain.myArticle[2] +'</a></li>');
            listContentMain.push('                    <li><i class="blog"></i><a target="_blank" href="'+ itemMain.myArticleHref[3] +'">'+ itemMain.myArticle[3] +'</a></li>');
            listContentMain.push('                    <li><i class="blog"></i><a target="_blank" href="'+ itemMain.myArticleHref[4] +'">'+ itemMain.myArticle[4] +'</a></li>');
            listContentMain.push('                    <li><i class="blog"></i><a target="_blank" href="'+ itemMain.myArticleHref[5] +'">'+ itemMain.myArticle[5] +'</a></li>');
            listContentMain.push('                </ul>');
            listContentMain.push('            </div><!--news_content结束-->');
            listContentMain.push('        </div><!--news结束-->');
            listContentMain.push('        <div class="news2">');
            listContentMain.push('            <div class="news_title">');
            listContentMain.push('                <h>'+ itemMain.aboutMeTitle +'</h>');
            listContentMain.push('                <a href="'+ itemMain.moreAboutMe +'">更多<img src="images/more_too.jpg"></a>');
            listContentMain.push('            </div><!--news_title结束-->');
            listContentMain.push('            <div class="news_content">');
            listContentMain.push('                <ul>');
            listContentMain.push('                    <li><i class="asdf"></i><a target="_blank" href="'+ itemMain.aboutMeHref[0] +'">'+ itemMain.aboutMe[0] +'</a></li>');
            listContentMain.push('                    <li><i class="asdf"></i><a target="_blank" href="'+ itemMain.aboutMeHref[1] +'">'+ itemMain.aboutMe[1] +'</a></li>');
            listContentMain.push('                    <li><i class="asdf"></i><a target="_blank" href="'+ itemMain.aboutMeHref[2] +'">'+ itemMain.aboutMe[2] +'</a></li>');
            listContentMain.push('                    <li><i class="asdf"></i><a target="_blank" href="'+ itemMain.aboutMeHref[3] +'">'+ itemMain.aboutMe[3] +'</a></li>');
            listContentMain.push('                    <li><i class="asdf"></i><a target="_blank" href="'+ itemMain.aboutMeHref[4] +'">'+ itemMain.aboutMe[4] +'</a></li>');
            listContentMain.push('                    <li><i class="asdf"></i><a target="_blank" href="'+ itemMain.aboutMeHref[5] +'">'+ itemMain.aboutMe[5] +'</a></li>');
            listContentMain.push('                </ul>');
            listContentMain.push('            </div><!--news_content结束-->');
            listContentMain.push('        </div><!--news2结束-->');
            listContentMain.push('        <div class="news3">');
            listContentMain.push('            <div class="news_title">');
            listContentMain.push('                <h>This&nbsp;is&nbsp;why&nbsp;we&nbsp;play</h>');
            listContentMain.push('                <a href="'+ itemMain.moreVideo +'">更多<img src="images/more_too.jpg" /></a>');
            listContentMain.push('            </div><!--news_title结束-->');
            listContentMain.push('            <div class="news_content">');
            listContentMain.push('                <div class="video_content">');
            //listContentMain.push('                    <embed src="'+ itemMain.videoSrc +'" allowFullScreen="true" quality="high" width="260" height="160" align="middle" allowScriptAccess="always"  type="audio/mpeg"></embed>');
            listContentMain.push('						<video poster="images/video.jpg" style="padding-left:30px" height="160" width="260" controls="controls" preload="auto">');
            listContentMain.push('  						<source  src="'+ itemMain.videoSrc +'" type="video/mp4" />');
            listContentMain.push('						</video>');
            listContentMain.push('                </div>');
            listContentMain.push('            </div><!--news_title3结束-->');
            listContentMain.push('        </div><!--news3结束-->');
            listContentMain.push('    </div><!--main_content结束-->');
            listContentMain.push('</div><!--main结束-->');
        });
        contentMain = listContentMain.join("");                 //  连成一句话
        $("#contentMain").append(contentMain);
        mainLoading = false;     //加载完毕
    }
});